<?php
namespace Admin\Controller;
use Think\Controller;
class webController extends AuthController {
    
   public function _initialize(){
        parent::_initialize();
		
        $hosttype = array('独立服务器','虚拟主机','云虚拟主机');
		$this->assign(array(
			'hosttype' => $hosttype,
			'now'      => time(),
		));
    }

    public function index(){
	    echo "hello world!";
        $this->display();
    }
	
	 public function domain(){
	    $domain    = M("domain");
		$groups    = M("group");
		$accounts  = M("account");
		$customer  = M("customer");
		import("ORG.Util.Page");// 导入分页类
		$count    = $domain->count();
		$page     = new \Think\Page($count,20);//tp3.2新增
		$show     = $page->show();
		$limit    = $page->firstRow.','.$page->listRows;
		
		/*用于判定是否已经过期超过30天*/
		$today = time();
	    $map.="(DATEDIFF(from_unixtime($today,'%Y-%m-%d'), from_unixtime(endtime,'%Y-%m-%d'))) < 30";
		
		$list     = $domain  -> join("abc_group as b on abc_domain.gid = b.gid")
		                     -> where($map) 
				             -> order("abc_domain.listorder desc, abc_domain.did desc") 
				             -> limit($limit)
							 -> select();
		$group    = $groups  -> order('listorder desc, gid desc')
		                     -> select();
		$account  = $accounts-> order('listorder desc, aid desc')
		                     -> select();
		$customer = $customer-> order('listorder desc, cid desc')
		                     -> select();
        
		/*查询对应所在账号名称*/
		foreach($list as $k => $arr){
		    if($arr['webaccount'] <> 0){
			   foreach($account as $a => $arr2){
			       if($arr['webaccount'] == $arr2['aid']){
				       $list[$k]['aname'] = $arr2['aname'];
				   }
			   }
			}else{
			    $list[$k]['aname'] = "外地域名";
			}
		}
		
		$this->assign(array(
		    'list'   => $list,
			'page'   => $show,
			'group'  => $group,
			'account'=> $account,
			'customer'=> $customer,
		));
        $this->display();
    }
	
	 //高级搜索
	 public function search(){
	    $domain  = M("domain");
		$groups  = M("group");
		$accounts= M("account");
		$customer= M("customer");
		$sotype  = "";
		import("ORG.Util.Page");// 导入分页类
		
		$group    = $groups  -> order('listorder desc, gid desc')
		                     -> select();
		$account  = $accounts-> order('listorder desc, aid desc')
		                     -> select();
		$customer = $customer-> order('listorder desc, cid desc')
		                     -> select();
							 
	    $sotype   =  I('param.sotype')? I('param.sotype'): '';//搜索类型 1急需续费域名 2 已过期域名 空为其他搜索
		$map      =  "";
		$num      =  0;
		$today    = time();
        if(empty($sotype)&& $sotype == ""){//正常关键词搜索
		    $keyword   =  trim(I('param.keyword','','htmlspecialchars'));
			$groupa    =  I('param.group')? I('param.group'): '';
			$accounta  =  trim(I('param.account'));
			$dstart    =  I('param.ddstart')? strtotime(I('param.ddstart')): '';
			$dend      =  I('param.ddend')? strtotime(I('param.ddend')): '';
			if(!empty($keyword)){
				$where['weburl']    =  array('like', '%'.$keyword.'%');
				$where['webname']   =  array('like', '%'.$keyword.'%');
				$where['hostip']    =  array('like', '%'.$keyword.'%');
				$where['content']   =  array('like', '%'.$keyword.'%');
				$where['linkman']   =  array('like', '%'.$keyword.'%');
				$where['_logic']    =  'or';
				$map['_complex']    =  $where;
			}
			if ($dstart && $dend){
				  $map['endtime']=array(array('egt',$dstart),array('elt',$dend)); 
			}elseif($dstart && $dend ==""){
				  $map['endtime']=array(array('egt',$dstart)); 
			}elseif($dstart=="" && $dend){
				  $map['endtime']=array(array('elt',$dend)); 
			}else{
				//$where['price']="";
			};//日期范围
			
			if(!empty($groupa)){
				 $map['gid'] = $groupa;
			}
			
			if(isset($accounta) && $accounta != ""){
				 $map['webaccount'] = $accounta;
			}
			
			$count =  $domain  -> where($map) 
				               -> order("abc_domain.listorder desc, abc_domain.did desc")  
							   -> count();;//重置分页总数
		    $page  = new \Think\Page($count,20);//tp3.2新增
		    $show  = $page->show();
		    $limit = $page->firstRow.','.$page->listRows;
			
			$list= $domain     -> where($map) 
				               -> order("abc_domain.listorder desc, abc_domain.did desc") 
							   -> limit($limit)
							   -> select();
							   
		}elseif(!empty($sotype) && $sotype ==1){//急需续费域名搜索
			   /*datediff函数用于比较两个时间之长，只计算天数*/
			   /*from_unixtime用于转换时间戳为标准格式，unix_timestamp为转换为时间戳格式*/
			   /*判定未来45天之内将要到期的域名。并且过期不能超过1天*/
			   $map ="(DATEDIFF(from_unixtime(endtime,'%Y-%m-%d'), from_unixtime($today,'%Y-%m-%d'))) < 45";
			   $map.=" AND (DATEDIFF(from_unixtime($today,'%Y-%m-%d'), from_unixtime(endtime,'%Y-%m-%d'))) < 1";
			   
			   $count =  $domain   -> where($map) 
				                   -> order("abc_domain.listorder desc, abc_domain.did desc")  
							       -> count();//重置分页总数
		       $page  = new \Think\Page($count,20);//tp3.2新增
		       $show  = $page->show();
		       $limit = $page->firstRow.','.$page->listRows;
			   
			   $list= $domain  -> where($map) 
				               -> order("abc_domain.listorder desc, abc_domain.did desc") 
							   -> limit($limit)
							   -> select();
							   
		}elseif(!empty($sotype) && $sotype ==2){//已过期域名搜索
		    $map['endtime'] = array('elt',time());
			
			$count =  $domain  -> where($map) 
							   -> count();;//重置分页总数
		    $page  = new \Think\Page($count,20);//tp3.2新增
		    $show  = $page->show();
		    $limit = $page->firstRow.','.$page->listRows;
			
		    $list= $domain     -> where($map) 
				               -> order("abc_domain.listorder desc, abc_domain.did desc") 
							   -> limit($limit)
							   -> select();
		}elseif(!empty($sotype) && $sotype ==3){//服务器到期查询
		       /*datediff函数用于比较两个时间之长，只计算天数*/
			   /*from_unixtime用于转换时间戳为标准格式，unix_timestamp为转换为时间戳格式*/
			   /*判定未来45天之内将要到期的域名。并且过期不能超过30天*/
			   $map = "hostend <> '' AND";
			   $map.="(DATEDIFF(from_unixtime(hostend,'%Y-%m-%d'), from_unixtime($today,'%Y-%m-%d'))) < 45";
			   $map.=" AND (DATEDIFF(from_unixtime($today,'%Y-%m-%d'), from_unixtime(hostend,'%Y-%m-%d'))) < 30";
			   
			   $count =  $domain   -> where($map) 
				                   -> order("listorder desc, did desc")  
							       -> count();//重置分页总数
		       $page  = new \Think\Page($count,20);//tp3.2新增
		       $show  = $page->show();
		       $limit = $page->firstRow.','.$page->listRows;
			   
			   $list= $domain  -> where($map) 
				               -> order("abc_domain.listorder desc, abc_domain.did desc") 
							   -> limit($limit)
							   -> select();
		}else{//其他情况
		    $count =  $domain  -> count();;//重置分页总数
		    $page  = new \Think\Page($count,20);//tp3.2新增
		    $show  = $page->show();
		    $limit = $page->firstRow.','.$page->listRows;
			
		    $list= $domain     -> order("listorder desc, did desc") 
							   -> limit($limit)
							   -> select();
		}//搜索分类结束
		
		
		foreach($list as $k => $arr){
		    /*查询对应所在账号名称*/
			if($arr['webaccount'] <> 0){
			   foreach($account as $a => $arr2){
				   if($arr['webaccount'] == $arr2['aid']){
					   $list[$k]['aname'] = $arr2['aname'];
				   }
			   }
			   
			}else{
				$list[$k]['aname'] = "外地域名";
			}
			
			/*查询分组名称*/
			foreach($group as $b => $arr3){
			    if($list[$k]['gid'] == $arr3['gid']){
				    $list[$k]['groupname'] = $arr3['groupname'];
				}	 
			}
		}

		$this->assign(array(
			'list'    => $list,
			'page'    => $show,
			'group'   => $group,
			'account' => $account,
			'sotype'  => $sotype,
			'customer'=> $customer,
			'count'=> $count,
		));
		
        $this->display();
    }
	
	
	/*网站内容编辑*/
	public function domain_edit(){
	    $did        = I('get.did');
		$domain     = M("domain");
		$account    = M("account");
		$group      = M("group");
		$customer   = M("customer");
		$where      = array('did' => $did);
		if (!empty($did)){
		     $arr = $domain->where('did = '.$did.'') 
						   ->order('did desc') 
						   ->find();
		}else{
		   $this->error("参数传递错误");
		}
		$dinfo     = json_decode($arr['dinfos'], true);//转成数组
		$ftp       = json_decode($arr['ftp'], true);//转成数组

		$group     = $group   -> order('listorder desc,gid desc') 
							  -> select();
		$account   = $account -> order('listorder desc,aid desc') 
							  -> select();
		$customer  = $customer-> order('listorder desc,cid desc') 
							  -> select();
		$this->assign(array(
				'data'        => $arr,
				'group'       => $group,
				'account'     => $account,
				'dinfo'       => $dinfo,
				'ftp'         => $ftp,
				'customer'    => $customer,
		));
        $this->display();
    }
	
	/*网站信息更新与添加*/
	public function domain_update(){
	    $did = I('get.did');
	    $domain = M("domain");
        
	   /*处理图片上传*/
		$upload = new \Think\Upload();// 实例化上传类  
		$upload->maxSize   =    3145728 ;// 设置附件上传大小  
		$upload->exts      =    array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型  
		$upload->savePath  =    '/'; // 设置附件上传目录
		$upload->saveName  =    array('date','YmdHis');
		$upload->subName   =    array('date','Ymd');
		$photo             =   $upload->upload(array($_FILES['photo']));

		$data['gid']       =   I('post.gid');
		$data['weburl']    =   str_replace("，",',',I('post.weburl'));//逗号转换
		$data['webname']   =   I('post.webname','','htmlspecialchars');
		$data['dstart']    =   strtotime(I('post.dstart','','htmlspecialchars'));
		$data['dend']      =   strtotime(I('post.dend','','htmlspecialchars'));
		$data['status']    =   I('post.status','','htmlspecialchars');
		$data['work']      =   I('post.work','','htmlspecialchars');
		$data['isowner']   =   I('post.isowner','','htmlspecialchars');
		$data['dinfos']    =   json_encode(I('post.dinfo','','htmlspecialchars'));
		$data['webaccount']=   I('post.webaccount','','htmlspecialchars');
		if($data['isowner']== 0){
		    $data['webaccount']= 0;
		}
		$data['hosttype']  =   I('post.hosttype','','htmlspecialchars');
		$data['hostip']    =   I('post.hostip');
		$data['hoststart'] =   strtotime(I('post.hoststart'));
		$data['hostend']   =   strtotime(I('post.hostend'));
		$data['hostaccount']=   I('post.hostaccount');
		$data['isbeian']   =   I('post.isbeian');
		$data['beian']     =   I('post.beian','','htmlspecialchars');
		//$data['beianer']   =   I('post.beianer','','htmlspecialchars');
		$data['ftp']       =   json_encode(I('post.ftp','','htmlspecialchars'));
		$data['linkman']   =   I('post.linkman','','htmlspecialchars');
		$data['phone']     =   I('post.phone','','htmlspecialchars');
		$data['wechat']    =   I('post.wechat','','htmlspecialchars');
		$data['qq']        =   I('post.qq','','htmlspecialchars');
		$data['qudao']     =   trim(I('post.qudao')) ? trim(I('post.qudao')) : "直属客户";
		$data['codetype']  =   I('post.codetype','','htmlspecialchars');
		$data['price']     =   I('post.price','','htmlspecialchars');
		$data['endtime']   =   strtotime(I('post.endtime','','htmlspecialchars'));
		$data['photo']     =   $photo ? "/Uploads".$photo[0]['savepath'].$photo['0']['savename'] : I('post.photo1');//防止图片覆盖
		$data['content']   =   I('post.content','','htmlspecialchars');
		$data['inputtime'] =   I('post.inputtime') ? strtotime(I('post.inputtime')) : time();
		$data['listorder'] =   I('post.listorder','','htmlspecialchars');
		
		if(trim(substr($data['weburl'],0,4)) == "http" || substr($data['weburl'],0,5) == "https" ){
		   $data['weburl'] = str_replace(array('http://','https://','/'),array('','',''),$data['weburl']);
	    }
		if(trim(substr($data['weburl'],-1)) == "/")
		$data['weburl'] = str_replace('/','',$data['weburl']);
	   
	   if (!isset($did) || $did ==""){//id为空表示新增
	        /*判定新增是一条还是多条*/
	        if(strpos($data['weburl'],',')){
			    $dataweb = array_filter(explode(',',$data['weburl']));//拆分并去除空内容
				for($i = 0; $i < count($dataweb); $i++){
				   $data['weburl'] = $dataweb[$i];
				   $count = $domain -> add($data);
				}
			}else{
			    $count = $domain -> add($data);
			}
		    
			if($count){
				  $this->success("添加成功",U('Web/domain'));
			}else{
				  $this->error("添加失败");	
			}
	   }else{//修改信息
	        if (IS_POST){
				$where['did'] = $did;
				$count = $domain ->where($where) -> save($data);
				if($count!== false){
					 $this->success("修改成功",U('Web/domain'));
			    }else{
				     $this->error("修改失败");	
			   }
			     
			}else{
			    $this->error("参数传递错误");
			}
	   
	   }
        
    }
	
	/*网站快速续费更新*/
	public function webfast_update(){
	    $did          = I('get.did');
	    $domain       = M("domain");
		$where['did'] = $did;
		$arr = $domain -> where($where) -> find();
		if($arr){
		    $data['endtime'] = strtotime("+1 year",$arr['endtime']);
			$data['dend']    = strtotime("+1 year",$arr['dend']);
			if(!empty($arr['hostend'])){
			    $data['hostend']     =  strtotime("+1 year",$arr['hostend']);
			}
			$arr2 = $domain -> where($where) -> save($data);
			if($arr2){
			    $this->redirect('Web/domain','', 1,'续费更新中...');
			}else{
			     $this->error("更新失败");
			}
		}else{
		    $this->error("参数错误",'domain');
		}
	}
	
	/*ajax获得分组所属备案信息*/
	public function ajaxget_beian(){
	    $gid   = I('get.gid');
		$group = M('group');
		$data  = "";
		if($gid =="" || $gid == 1){
		   $data = "";
		}else{
		    $where['gid'] = $gid;
			$data = $group -> where($where) -> getField('beian');
		}
		$this->ajaxReturn($data); 
	}
	
	
	/*新增网站信息*/
    public function domain_add(){
	     $group     = M("group");
		 $account   = M("account");
		 $customer  = M("customer");
		 $group     = $group   -> order('listorder desc,gid desc') 
					  		   -> select();
		 $account   = $account -> order('listorder desc,aid desc') 
							   -> select();
		 $customer  = $customer-> order('listorder desc,cid desc') 
							   -> select();
		 $now       = time();
		 $this->assign(array(
		     'now'      => $now,
			 'group'    => $group,
			 'account'  => $account,
			 'customer' => $customer
		 ));
	     $this->display();
	}	
	
	/*ajax查看密码*/
	public function lookpwd(){
	    $aid = I('get.aid');
		$account   = M("account");
		$where['aid'] = $aid;
		$data    = "";
		if (!empty($aid)){
		    $password = $account->where($where) -> getField("accountpwd");
			if($password){
			    $data = $password;
			}else{
			    $data = "";
			}
		}
		$this->ajaxReturn($data);  
	}
	
	/*域名删除*/
	public function domain_del(){
	     $did     = I('get.did');//单条
		 $dids    = I('post.did');//批量
		 $dids    = join(',', $dids);
		 $domain  = M("domain");
		if (!empty($did) && empty($dids) && isset($did)){
		    $where['did'] = $did;
			$count = $domain->where($where)->delete();
		}else{
			$count = $domain->where(array('did' => array('in', $dids)))->delete();
		}
		if($count){
		    $this->success("删除成功",U('web/domain'));
		}else{
		    $this->error("删除失败");	
		}
	}
	
	
	/*以下是账号信息管理*/
	/*注册账号信息*/
	public function account(){
	    $account = M("account");
		import("ORG.Util.Page");// 导入分页类
		$count = $account->count();
		$page  = new \Think\Page($count,10);//tp3.2新增
		$show  = $page->show();
		$limit = $page->firstRow.','.$page->listRows;
		
		$list= $account -> order("listorder desc, aid desc") 
		                 -> limit($limit)
						 ->select();
		$this->assign(array(
		    'list' => $list,
			'page' => $show,
		));
        $this->display();
    }
	
	/*账号编辑模板*/
	public function account_edit(){
	     $aid = I("get.aid");
		 $account = M("account");
		 $where      = array('aid' => $aid);
		 if (!empty($aid)){
		     $arr = $account->where('aid = '.$aid.'') 
						   ->order('aid desc') 
						   ->find();
		 }else{
		    $this->error("参数传递错误");
		 }
		 
		$this->assign(array(
		    'data' => $arr,
		));
        $this->display();
	}
	
	/*新增/修改账号信息*/
	public function account_update(){
	    $aid         =   I('get.aid');
	    $account    =   M("account"); 
		
		if (IS_POST){
			 $data['aname']        =  trim(I('post.aname','','htmlspecialchars'));
			 $data['aurl']         =  trim(I('post.aurl','','htmlspecialchars'));
			 $data['account']      =  trim(I('post.account','','htmlspecialchars'));
			 $data['accountpwd']   =  trim(I('post.accountpwd','','htmlspecialchars'));
			 $data['phone']        =  trim(I('post.phone','','htmlspecialchars'));
			 $data['email']        =  trim(I('post.email','','htmlspecialchars'));
			 $data['content']      =  trim(I('post.content','','htmlspecialchars'));
			 $data['inputtime']    =  I("post.inpuuttime") ? strtotime(trim(I('post.inputtime','','htmlspecialchars'))) : time();
			 $data['listorder']    =  I('post.listorder') ? trim(I('post.listorder')): 0;

			 if(trim(substr($data['aurl'],0,4)) <> "http"){
			    $data['aurl'] = "http://".$data['aurl'];
			 }
		}
		
	    if (!isset($aid) || $aid ==""){//id为空表示新增
	          $count = $account -> add($data);
			  if($count){
				  $this->success("添加成功",U('Web/account'));
			  }else{
				  $this->error("添加失败");	
			  }
		}else{//修改信息
		      $where['aid'] = $aid;
	          $count = $account->where($where) -> save($data);
			  if($count){
				  $this->success("修改成功",U('web/account'));
			  }else{
				  $this->error("修改失败");	
			  }
		}
	}
	
	/*账号删除*/
	public function account_del(){
	     $aid     = I('get.aid');//单条
		 $aids    = I('post.aid');//批量
		 $aids    = join(',', $aids);
		 $account = M("account");
		if (!empty($aid) && empty($aids) && isset($aid)){
		    $where['aid'] = $aid;
			$count = $account->where($where)->delete();
		}else{
			$count = $account->where(array('aid' => array('in', $aids)))->delete();
		}
		if($count){
		    $this->success("删除成功",U('web/account'));
		}else{
		    $this->error("删除失败");	
		}
	}
	
	/*以下是域名分组信息管理*/
	/*分组信息*/
	public function group(){
	    $group = M("group");
		import("ORG.Util.Page");// 导入分页类
		$count = $group->count();
		$page  = new \Think\Page($count,10);//tp3.2新增
		$show  = $page->show();
		$limit = $page->firstRow.','.$page->listRows;
		
		$list= $group -> order("listorder desc, gid desc") 
		                 -> limit($limit)
						 ->select();
		$this->assign(array(
		    'list' => $list,
			'page' => $show,
			'now'  => time(),
		));
        $this->display();
    }
	
	/*新增/修改分组信息*/
	public function group_update(){
	    $gid         =   I('get.gid');
	    $group       =   M("group"); 
		
		if (IS_POST){
			 $data['groupname']    =  trim(I('post.groupname','','htmlspecialchars'));
			 $data['beian']        =  I('post.beian') ? trim(I('post.beian','','htmlspecialchars')) : "";
			 $data['content']      =  trim(I('post.content','','htmlspecialchars'));
			 $data['inputtime']    =  I("post.inpuuttime") ? strtotime(trim(I('post.inputtime','','htmlspecialchars'))) : time();
			 $data['listorder']    =  I('post.listorder') ? trim(I('post.listorder')): 0;
		}
	    if (!isset($gid) || $gid ==""){//id为空表示新增
	          $count = $group -> add($data);
			  if($count){
				  $this->success("添加成功",U('Web/group'));
			  }else{
				  $this->error("添加失败");	
			  }
		}else{//修改信息
		      $where['gid'] = $gid;
			  
			  /*获取网站数量*/
			  $domain = M("domain"); 
			  $data['webnum']  = $domain ->where($where) ->count();
	          $count = $group   ->where($where) -> save($data);
			  if($count){
				  $this->success("修改成功",U('web/group'));
			  }else{
				  $this->error("修改失败");	
			  }
		}
	}
	
	/*分组编辑*/
	public function group_edit(){
	    $gid        = I('get.gid');
		$group      = M("group");
		$where      = array('gid' => $gid);
		if (!empty($gid)){
		     $arr = $group->where('gid = '.$gid.'') 
						   ->order('gid desc') 
						   ->find();
		}else{
		   $this->error("参数传递错误");
		}
		$this->assign(array(
				'data'        => $arr,
		));
        $this->display();
    }
	
	/*更新分组域名统计信息*/
	public function domain_count(){
	     $domain = M("domain");
		 $group  = M("group");
		 
		 $groups  =  $group ->order("listorder desc, gid desc") -> select();
		 $num = count($groups);
		 foreach($groups as $k => $r){
		     //echo $r['gid'];
		     $where['gid'] =  $r['gid'];
			 $webnum = $domain ->where($where) ->count();
			 $data['webnum'] = $webnum;
			 $group -> where(array('gid' => $r[gid]))-> save($data);
		 }
		 
		 redirect('group', 1, '正在更新中...');
	}
	
	/*分组删除*/
	public function group_del(){
	     $gid     = I('get.gid');//单条
		 $gids    = I('post.gid');//批量
		 $gids    = join(',', $gids);
		 $group   = M("group");
		if (!empty($gid) && empty($gids) && isset($gid)){
		    $where['gid'] = $gid;
			$count = $group->where($where)->delete();
		}else{
			$count = $group->where(array('gid' => array('in', $gids)))->delete();
		}
		if($count){
		    $this->success("删除成功",U('web/group'));
		}else{
		    $this->error("删除失败");	
		}
	}
	
	/*外地网站统计*/
	public function waidi(){
	    $waidi    = M("waidi");
		import("ORG.Util.Page");// 导入分页类
		$count    = $waidi->count();
		$page     = new \Think\Page($count,10);//tp3.2新增
		$show     = $page->show();
		$limit    = $page->firstRow.','.$page->listRows;
		
		$list     = $waidi-> order("listorder desc, wid desc") 
				            -> limit($limit)->select();
		
		$this->assign(array(
		    'list'   => $list,
			'page'   => $show,
		));
        $this->display();
    }
	
	/*外地网站编辑*/
	public function waidi_edit(){
	    $wid        = I('get.wid');
		$waidi      = M('waidi');
		$where      = array('wid' => $wid);
		if (!empty($wid)){
		     $arr = $waidi->where('wid = '.$wid.'') 
						   ->order('wid desc') 
						   ->find();
		}else{
		   $this->error("参数传递错误");
		}
		$this->assign(array(
				'data'        => $arr,
		));
        $this->display();
    }
	
	/*新增/修改外地域名*/
	public function waidi_update(){
	    $wid        =   I('get.wid');
	    $waidi      =   M("waidi"); 
		
		if (IS_POST){
			 $data['webname']      =  trim(I('post.webname','','htmlspecialchars'));
			 $data['weburl']       =  trim(I('post.weburl','','htmlspecialchars'));
			 $data['contact']      =  trim(I('post.contact','','htmlspecialchars'));
			 $data['contactinfo']  =  trim(I('post.contactinfo','','htmlspecialchars'));
			 $data['domaininfo']   =  trim(I('post.domaininfo','','htmlspecialchars'));
			 $data['ftpinfo']      =  trim(I('post.ftpinfo','','htmlspecialchars'));
			 $data['other']        =  trim(I('post.ohter','','htmlspecialchars'));
			 $data['finishtime']   =  I("post.finishtime") ? strtotime(trim(I('post.finishtime','','htmlspecialchars'))) : time();
			 $data['inputtime']    =  I("post.inpuuttime") ? strtotime(trim(I('post.inputtime','','htmlspecialchars'))) : time();
			 $data['ismanage']       =  I('post.ismanage') ? trim(I('post.ismanage')): 1;
			 $data['status']       =  I('post.status') ? trim(I('post.status')): 1;
			 $data['listorder']    =  I('post.listorder') ? trim(I('post.listorder')): 0;

			 if(trim(substr($data['weburl'],0,4)) <> "http"){
			    $data['weburl'] = "http://".$data['weburl'];
			 }
		}
		
	    if (!isset($wid) || $wid ==""){//id为空表示新增
	          $count = $waidi -> add($data);
			  if($count){
				  $this->success("添加成功",U('Web/waidi'));
			  }else{
				  $this->error("添加失败");	
			  }
		}else{//修改信息
		      $where['wid'] = $wid;
	          $count = $waidi->where($where) -> save($data);
			  if($count){
				  $this->success("修改成功",U('web/waidi'));
			  }else{
				  $this->error("修改失败");	
			  }
		}
	}
	
	/*外地网站删除*/
	public function waidi_del(){
	     $wid     = I('get.wid');//单条
		 $wids    = I('post.wid');//批量
		 $wids    = join(',', $wids);
		 $waidi   = M("waidi");
		if (!empty($wid) && empty($wids) && isset($wid)){
		    $where['wid'] = $wid;
			$count = $waidi->where($where)->delete();
		}else{
			$count = $waidi->where(array('wid' => array('in', $wids)))->delete();
		}
		if($count){
		    $this->success("删除成功",U('web/waidi'));
		}else{
		    $this->error("删除失败");	
		}
	}
	
	
	/*域名导出*/
	public function export_domain(){
	    $domain    = M("domain");
		$groups    = M("group");
		$accounts  = M("account");
		$hosttype = array('独立服务器','虚拟主机','云虚拟主机');
		
		$list     = $domain  -> join("abc_group as b on abc_domain.gid = b.gid")
		                     -> where('abc_domain.status = 1') 
				             -> order("abc_domain.listorder desc, abc_domain.did desc") 
							 -> select();
		$group    = $groups  -> order('listorder desc, gid desc')
		                     -> select();
		$account  = $accounts-> order('listorder desc, aid desc')
		                    -> select();
        
		/*查询对应所在账号名称*/
		foreach($list as $k => $arr){
		    if($arr['webaccount'] <> 0){
			   
			   foreach($account as $a => $arr2){
			       if($arr['webaccount'] == $arr2['aid']){
				       $list[$k]['aname'] = $arr2['aname'];
				   }
			   }
			   
			}else{
			    $list[$k]['aname'] = "外地域名";
			}
		}
		
	    Vendor('PHPExcel.PHPExcel');
		$objExcel = new \PHPExcel();
        $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
		
		$objExcel->getActiveSheet()->setCellValue('A1','ID');
		$objExcel->getActiveSheet()->setCellValue('B1', "域名");
		$objExcel->getActiveSheet()->setCellValue('C1', "网站名称");
		$objExcel->getActiveSheet()->setCellValue('D1', "分组");
		$objExcel->getActiveSheet()->setCellValue('E1', "状态");
		$objExcel->getActiveSheet()->setCellValue('F1', "启用");
		$objExcel->getActiveSheet()->setCellValue('G1', "到期时间");
		$objExcel->getActiveSheet()->setCellValue('H1', "域名到期时间");
		$objExcel->getActiveSheet()->setCellValue('I1', "域名管理权");
		$objExcel->getActiveSheet()->setCellValue('J1', "服务器类型");
		$objExcel->getActiveSheet()->setCellValue('K1', "服务器IP");
		$objExcel->getActiveSheet()->setCellValue('L1', "服务器时间");
		$objExcel->getActiveSheet()->setCellValue('M1', "备案信息");
		$objExcel->getActiveSheet()->setCellValue('N1', "联系人");
		$objExcel->getActiveSheet()->setCellValue('O1', "电话");
		$objExcel->getActiveSheet()->setCellValue('P1', "微信");
		$objExcel->getActiveSheet()->setCellValue('Q1', "Q Q");
		$objExcel->getActiveSheet()->setCellValue('R1', "类型");
		$objExcel->getActiveSheet()->setCellValue('S1', "输入时间");
		
		//设置当前的sheet
		$objExcel->setActiveSheetIndex(0);
		//设置sheet的name
		$objExcel->getActiveSheet()->setTitle('全部网站列表');
		
		//文字对齐方式  锚：bbb
	    $objExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objExcel->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);  
	
		//设置默认行高
        $objExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(30);
		$objExcel->getDefaultStyle()->getFont()->setSize(12);
		
		//设置填充颜色
        $objExcel->getActiveSheet()->getStyle('A1:S1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
        $objExcel->getActiveSheet()->getStyle('A1:S1')->getFill()->getStartColor()->setARGB('#009688');
	   
	   /*设置字体颜色*/
	   $objExcel->getActiveSheet()->getStyle('A1:S1')->getFont()->getColor()->setARGB(\PHPExcel_Style_Color::COLOR_WHITE);
	   $objExcel->getActiveSheet()->getStyle('E')->getFont()->getColor()->setARGB('#009688');
	   
	   // 高置列的宽度
		$objExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
		$objExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
		$objExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$objExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('E')->setWidth(8);
		$objExcel->getActiveSheet()->getColumnDimension('F')->setWidth(8);
		$objExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
		$objExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('K')->setWidth(18);
		$objExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
		$objExcel->getActiveSheet()->getColumnDimension('M')->setWidth(25);
		$objExcel->getActiveSheet()->getColumnDimension('N')->setWidth(10);
		$objExcel->getActiveSheet()->getColumnDimension('O')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('P')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(15);
		$objExcel->getActiveSheet()->getColumnDimension('R')->setWidth(10);
		$objExcel->getActiveSheet()->getColumnDimension('S')->setWidth(15);
	    /*锁定单元格*/
		$objExcel->getActiveSheet()->freezePane("A2");
		
		$count = count($list);//$driver 为数据库表取出的数据
		for ($i = 2; $i <= $count+1; $i++) {
			$stat    = $list[$i-2]['status'] ? "正常" : "过期";
			$work    = $list[$i-2]['work'] ? "启用" : "未启用";
			$isowner = $list[$i-2]['isowner'] ? "在我处" : "不在我处";
			
		    $objExcel->getActiveSheet()->setCellValue('A' . $i, $list[$i-2]['did']); 
		    $objExcel->getActiveSheet()->setCellValue('B' . $i, $list[$i-2]['weburl']); 
		    $objExcel->getActiveSheet()->setCellValue('C' . $i, $list[$i-2]['webname']); 
		    $objExcel->getActiveSheet()->setCellValue('D' . $i, $list[$i-2]['groupname']);
			$objExcel->getActiveSheet()->setCellValue('E' . $i, $stat);
			$objExcel->getActiveSheet()->setCellValue('F' . $i, $work);
			$objExcel->getActiveSheet()->setCellValue('G' . $i, date('Y-m-d',$list[$i-2]['endtime']));
			$objExcel->getActiveSheet()->setCellValue('H' . $i, date('Y-m-d',$list[$i-2]['dstart'])."  ~ ".date('Y-m-d',$list[$i-2]['dend']));
			$objExcel->getActiveSheet()->setCellValue('I' . $i, $isowner);
			$objExcel->getActiveSheet()->setCellValue('J' . $i, $hosttype[$list[$i-2]['hosttype']]);
			$objExcel->getActiveSheet()->setCellValue('K' . $i, $list[$i-2]['hostip']);
			$objExcel->getActiveSheet()->setCellValue('L' . $i, date('Y-m-d',$list[$i-2]['hoststart'])."  ~ ".date('Y-m-d',$list[$i-2]['hostend']));
			$objExcel->getActiveSheet()->setCellValue('M' . $i, $list[$i-2]['beian']);
			$objExcel->getActiveSheet()->setCellValue('N' . $i, $list[$i-2]['linkman']);
			$objExcel->getActiveSheet()->setCellValue('O' . $i, $list[$i-2]['phone']);
			$objExcel->getActiveSheet()->setCellValue('P' . $i, $list[$i-2]['wechat']);
			$objExcel->getActiveSheet()->setCellValue('Q' . $i, $list[$i-2]['qq']);
			$objExcel->getActiveSheet()->setCellValue('R' . $i, $list[$i-2]['qudao']);
			$objExcel->getActiveSheet()->setCellValue('S' . $i, date('Y-m-d',$list[$i-2]['inputtime']));
		}
	   
	   $objExcel->setActiveSheetIndex(); 
	   $excel_name = "全部域名".date('Y-m-d',time());
	   header('Content-Type: applicationnd.ms-excel'); 
	   header('Content-Disposition: attachment;filename='.$excel_name.'.xls'); 
	   header('Cache-Control: max-age=0'); 
		
	   $objWriter->save('php://output'); 
	   exit;
	
	} 
	
	
}